from PySide2.QtWidgets import QApplication, QMainWindow, QPushButton, QPlainTextEdit, QMessageBox

app = QApplication([])
# 创建窗口,提供整个图形界面的底层管理功能

window = QMainWindow()
window.resize(500, 400)
window.move(300, 310)#相对父元素(显示器)移动这些
window.setWindowTitle('薪资统计')

textEdit = QPlainTextEdit(window)
textEdit.setPlaceholderText("请输入薪资表")
textEdit.move(10,25)#相对父元素(不是显示器,是window 窗口 块)移动这些
textEdit.resize(300,350)

button = QPushButton('统计', window)
button.move(380,80)

def handleCalc(self): #slot
    info = textEdit.toPlainText()

    salary_above_20k = ''
    salary_below_20k = ''
    for line in info.splitlines():
        if not line.strip():
            continue
        parts = line.split(' ')

        parts = [p for p in parts if p]
        name,salary,age = parts
        if int(salary) >= 20000:
            salary_above_20k += name + '\n'
        else:
            salary_below_20k += name + '\n'

    QMessageBox.about(window,
                      '统计结果',
                      f'''薪资20000 以上的有：\n{salary_above_20k}
                    \n薪资20000 以下的有：\n{salary_below_20k}'''
                      )

button.clicked.connect(handleCalc) #槽,把水引到槽里,数据就被槽处理了 sign slot

window.show() #只是显示一下

app.exec_() #有这一行,程序就会进行一个死循环,直到用户关闭窗口,不会自动退出


#张三  4560 25
#李四  35767 23
#王五  14346 42
